package com.market.sys.common;/*
 *文件名: Result
 *创建时间:2022/12/29 9:36
 *version: 1.0
 *since: 1.0
 */

public class Result<T> {

    /**
     * 状态码200
     */
    public static final Integer CODE_200 = 200;


    /**
     * 状态码500
     */
    public static final Integer CODE_500 = 500;


    /**
     * 状态码401
     */
    public static final Integer CODE_401 = 401;


    /**
     * 状态码403
     */
    public static final Integer CODE_403 = 403;

    /**
     * 返回的数据内容
     */
    private T data;


    /**
     * 返回的消息内容
     */
    private String message;


    /**
     * 状态码
     */
    private Integer code;


    public Result() {
    }

    public static Result<?> success() {
        Result<?> result = new Result<>();
        result.setCode(CODE_200);
        result.setData(null);
        result.setMessage("success");
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(CODE_200);
        result.setMessage("success");
        return result;
    }

    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<>();
        result.setData(null);
        result.setCode(CODE_200);
        result.setMessage(msg);
        return result;
    }

    public static <T> Result<T> success(T data, String msg) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setCode(CODE_200);
        result.setMessage(msg);
        return result;
    }

    public static Result<?> error() {
        Result<?> result = new Result<>();
        result.setMessage("error");
        result.setCode(CODE_500);
        return result;
    }

    public static Result<?> error(String message) {
        Result<?> result = new Result<>();
        result.setMessage(message);
        result.setCode(CODE_500);
        return result;
    }

    public static Result<?> error(String message, Integer code) {
        Result<?> result = new Result<>();
        result.setMessage(message);
        result.setCode(code);
        return result;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
